<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateAccessTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('access', ['comment' => '菜单权限', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('parent_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '上级ID'])
            ->addColumn('name', 'string', ['limit'  =>  191, 'default' => '', 'comment' => '权限标识'])
            ->addColumn('title', 'string', ['limit'  =>  255, 'default' => '', 'comment' => '菜单名称'])
            ->addColumn('type', 'string', ['limit'  =>  30, 'default' => '', 'comment' => '类型'])
            ->addColumn('icon', 'string', ['limit'  =>  255, 'null' => true, 'default' => null, 'comment' => '图标'])
            ->addColumn('params', 'string', ['limit'  =>  255, 'null' => true, 'default' => null, 'comment' => '参数'])
            ->addColumn('weigh', 'integer', ['limit'  =>  8, 'default' => 0, 'comment' => '权重'])
            ->addColumn(Column::enum('status', ['show', 'hidden', 'disabled'])->setDefault('show')->setComment('状态'))
            ->addIndex('name', ['unique'  =>  true])
            ->create();
    }


    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('access');
        $table->drop();
    }
}
